package com.ujoku.service.impl;

import com.labillusion.core.database.base.mybatis.dao.BaseDao;
import com.labillusion.core.database.base.mybatis.service.base.impl.BaseServiceImpl;
import com.ujoku.dao.MyListItemDao;
import com.ujoku.domain.MyListItem;
import com.ujoku.service.CdnService;
import com.ujoku.service.MyListItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 14-10-19.
 */
@Service
public class MyListItemServiceImpl extends BaseServiceImpl<MyListItem> implements MyListItemService<MyListItem> {

    @Autowired
    private MyListItemDao dao;

    @Autowired
    private CdnService cdnService;

    @Override
    protected BaseDao<MyListItem> getBaseDao() {
        return dao;
    }

    @Override
    public List<MyListItem> selectList(Map<String,Object> query){
        List<MyListItem> myListItemList = super.selectList(query);
        myListItemList.forEach(i->i.setMediumImage(cdnService.buildGoodsImage(i.getGoodsId(), CdnService.Goods_Medium, i.getGoodsUpdateTime().getTime())));

        return myListItemList;
    }

    @Override
    public List<MyListItem> selectMyListItem(String myListId){
        Map<String,Object> query = new HashMap<>();
        query.put("myListId",myListId);

        List<MyListItem> myListItemList = this.selectList(query);
        myListItemList.forEach(i->i.setMediumImage(cdnService.buildGoodsImage(i.getGoodsId(), CdnService.Goods_Medium, i.getGoodsUpdateTime().getTime())));

        return myListItemList;
    }

    @Override
    public MyListItem selectOneMyListItem(String myListId,String id){
        Map<String,Object> query = new HashMap<>();
        query.put("myListId",myListId);
        query.put("id",id);

        return this.selectOne(query);
    }


    @Override
    public List<MyListItem> selectFriendItemList(Map<String, Object> query) {

        return dao.selectFriendItemList(query);
    }

    @Override
    public int selectFriendItemCount(Map<String, Object> query) {

        return dao.selectFriendItemCount(query);
    }
}
